﻿using AutoMapper;
using Caltech.Extensions;
using Caltech.Models;
using Caltech.Service.Common;
using CaltechSoft.Service.EntityFW.Entity;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Caltech.Controllers
{
    [HasAccess(Areas.Config)]
    public class RoleController : ApiController
    {
        public RoleManager<Role> Repository { get; set; }

        public RoleController(RoleManager<Role> repository)
        {
            Repository = repository;
        }

        public IHttpActionResult Get()
        {
            var entities = Repository.Roles.ToList();
            return Ok(Mapper.Map<IEnumerable<RoleModel>>(entities));
        }

        public IHttpActionResult Put(RoleModel model)
        {
            var entity = Repository.FindById(model.Id.ToString());
            entity.Areas = model.Areas;
            entity.LandingArea = model.LandingArea;

            Repository.Update(entity);

            return Ok();
        }
    }


}
